package com.wlf.demo.mp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlf.demo.mp.entity.User;
import com.wlf.demo.mp.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wan Email-wlf18726994755@163.com
 * @version 1.0
 * @className UserPlusController
 * @date 2020/6/5 14:06
 **/
@RestController
@RequestMapping("/userPlus")
public class UserPlusController {
    @Resource
    private IUserService iUserService;

    @GetMapping("/getUserListPage")
    public Map<String,Object> getUserListPage(){
        Map<String, Object> map = new HashMap<>();
        //查询成绩高于80的用户
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.lambda().gt(User::getFraction,80);
        List<User> list = iUserService.list(wrapper);
        map.put("userfraction",list);

        //查询年龄大于5岁，小于等于15岁的同学
        QueryWrapper<User> wrapper1 = new QueryWrapper<>();
        wrapper1.lambda().gt(User::getAge,5);
        wrapper1.lambda().le(User::getAge,15);
        List<User> list1 = iUserService.list(wrapper1);
        map.put("userAge5~15",list1);

        //模糊查询技能字段带有画的数据，并且按照年龄降序
        QueryWrapper<User> wrapper2 = new QueryWrapper<>();
        wrapper2.lambda().like(User::getSkill,"画");
        wrapper2.lambda().orderByDesc(User::getAge);
        List<User> list2 = iUserService.list(wrapper2);
        map.put("UserAgeSkill", list2);

        //模糊查询名字带有"小"或者年龄大于18的学生
        QueryWrapper<User> wrapper3 = new QueryWrapper<>();
        wrapper3.lambda().like(User::getName,"小");
        wrapper3.lambda().or().gt(User::getAge,18);
        List<User> list3 = iUserService.list(wrapper3);
        map.put("userOr",list3);

        //查询评价不为null的学生，并分页
        IPage<User> page = new Page<>();
        page.setCurrent(1);
        page.setSize(5);
        QueryWrapper<User> wrapper4 = new QueryWrapper<>();
        wrapper4.lambda().isNotNull(User::getEvaluate);
        page =  iUserService.page(page,wrapper4);
        map.put("userPage",page);

        return map;
    }
}
